{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7b3a8453",
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "x_pi = 3.14159265358979324 * 3000.0 / 180.0\n",
    "pi = 3.1415926535897932384626  # π\n",
    "a = 6378245.0  # 长半轴\n",
    "ee = 0.00669342162296594323  # 偏心率平方\n",
    "coordinate = []\n",
    "lng = []\n",
    "lat = []\n",
    "converted_lng = []\n",
    "converted_lat = []\n",
    "def gcj02_to_wgs84(series):\n",
    "    lng=series['经度']\n",
    "    lat=series['纬度']\n",
    "    if out_of_china(lng, lat):\n",
    "        return [lng, lat]\n",
    "    dlat = _transformlat(lng - 105.0, lat - 35.0)\n",
    "    dlng = _transformlng(lng - 105.0, lat - 35.0)\n",
    "    radlat = lat / 180.0 * pi\n",
    "    magic = math.sin(radlat)\n",
    "    magic = 1 - ee * magic * magic\n",
    "    sqrtmagic = math.sqrt(magic)\n",
    "    dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi)\n",
    "    dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi)\n",
    "    mglat = lat + dlat\n",
    "    mglng = lng + dlng\n",
    "    r_lng=lng * 2 - mglng\n",
    "    r_lat=lat * 2 - mglat\n",
    "    return r_lng,r_lat\n",
    "def _transformlat(lng, lat):\n",
    "    ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + \\\n",
    "          0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng))\n",
    "    ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 *\n",
    "            math.sin(2.0 * lng * pi)) * 2.0 / 3.0\n",
    "    ret += (20.0 * math.sin(lat * pi) + 40.0 *\n",
    "            math.sin(lat / 3.0 * pi)) * 2.0 / 3.0\n",
    "    ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 *\n",
    "            math.sin(lat * pi / 30.0)) * 2.0 / 3.0\n",
    "    return ret\n",
    "\n",
    "def _transformlng(lng, lat):\n",
    "    ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + \\\n",
    "          0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng))\n",
    "    ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 *\n",
    "            math.sin(2.0 * lng * pi)) * 2.0 / 3.0\n",
    "    ret += (20.0 * math.sin(lng * pi) + 40.0 *\n",
    "            math.sin(lng / 3.0 * pi)) * 2.0 / 3.0\n",
    "    ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 *\n",
    "            math.sin(lng / 30.0 * pi)) * 2.0 / 3.0\n",
    "    return ret\n",
    "def out_of_china(lng, lat):\n",
    "    \"\"\"\n",
    "    判断是否在国内，不在国内不做偏移\n",
    "    :param lng:\n",
    "    :param lat:\n",
    "    :return:\n",
    "    \"\"\"\n",
    "    return not (lng > 73.66 and lng < 135.05 and lat > 3.86 and lat < 53.55)\n",
    "import pandas as pd\n",
    "#KeyWords=['医院','酒店',\"购物中心\",\"政府机构\",\"学校\",'公交车站','餐饮','公司']\n",
    "KeyWords=['地铁站']\n",
    "for KeyWord in KeyWords:\n",
    "    df=pd.read_csv('D:/test/高德_武汉_'+str(KeyWord)+'.csv')\n",
    "    df[['wgs_84_lng','wgs_84_lat']]=df[['经度','纬度']].apply(gcj02_to_wgs84, axis=1,result_type=\"expand\")\n",
    "    df.to_csv('C:/Users/18295335197/Desktop/大创/数据/武汉测试数据/武汉_'+str(KeyWord)+'_84.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "012d0418",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
